const { openSavePointFile } = require("../../../src/service/savePointFile");
const { formatDate, info, errorInfo } = require("../../../src/utils");


info(__dirname);

const testData = {
    a: 1,
    b: { bb: 2 },
    cc: [1234, '5678'],
    style: {
        'background-color': '#112233'
    }
}


async function write0() {
    try {
        const spf = await openSavePointFile(__dirname, 'testFile');
        spf.setScheme('v2Element');
        const time = formatDate(new Date(), 'yyMMdd-hhmmssS');
        await spf.writeSavePoint(time, '测试1', JSON.stringify(testData));
    } catch (e) {
        errorInfo(e);
    }
}

async function read0() {
    try {
        const spf = await openSavePointFile(__dirname, 'testFile');
        info(spf.scheme, spf.indexes);
        for (let time in spf.indexes) {
            const data = await spf.readSavePoint(time);
            info(time,data);
        }

    } catch (e) {
        errorInfo(e);
    }
}


read0();